{extend name="main/index" /}
{block name="main"}

<!-- JQ ajax -->
<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>  
        <script>  
            function l(id){
            	window.location="{:url('admin/priv/del')}?id="+id;
            }
              
              
            function ajaxDel(id){  
            	$.ajax({  
                    type:"GET",  
                    url:"{:url('admin/priv/del')}?id="+id,  
                    success:function(data){
                    	if(data=="no pri"){
                    		alert("你没有删除的权限");
                    	}else if(data){
                    		alert("删除成功");
                    		location.reload();
                    	}else{
                    		 alert("删除失败");
                    	}
                     
                    }

                });  
            }
            
            function ajaxEdit(id){  
            	$.ajax({  
                    type:"GET",  
                    url:"{:url('admin/priv/edit')}?id="+id,  
                    success:function(data){
                    	if(data=="no pri"){
                    		alert("你没有权限查看该信息");
                    	}else if(data==false){
                    		alert("查询详情失败");
                    	}else{
                    		$('#myModal').modal('show');
                    		$('#pid').val(data['id']);
                    		$("#ep").val(data['pri_name']);
                    		$("#ec").val(data['controller_name']);
                    		$("#ea").val(data['action_name']);
                    		
                    	}
                    		
                    },

                });  
            }
            
             function ajaxPost(){  
                var formData = $("#edit").serialize();  
                
                $.ajax({  
                    type:"post",  
                    url:"{:url('admin/priv/doEdit')}",  
                    data:formData,
                    success:function(data){  
                       if(data=="no pri"){
                    		alert("你没有权限修改！");
                    	}else if(data==true){
                    		alert("提交成功");
                        	location.reload();
                    	}else{
                    		alert("提交失败！事务回滚");
                    	}
                    },
                      

                });  
            }  
            
              
		</script> 
		
		
<!-- Start right content -->
<div class="content-page">
    <!-- ============================================================== -->
    <!-- Start Content here -->
    <!-- ============================================================== -->
    <div class="content">
        <!-- Page Heading Start -->
        <div class="page-heading">
            <h1><i class='fa fa-table'></i> 权限模块</h1>
            </div>
        <!-- Page Heading End-->                <!-- Your awesome content goes here -->
        	<div class="col-md-2"></div>
        	
            <div class="col-md-8">
                <div class="widget">
                    <div class="widget-header transparent">
                        <h2><strong>权限列表</strong> </h2>
                        <div class="additional-btn">
                            <a href="#" class="hidden reload"><i class="icon-ccw-1"></i></a>
                            <a href="#" class="widget-toggle"><i class="icon-down-open-2"></i></a>
                            <a href="#" class="widget-close"><i class="icon-cancel-3"></i></a>
                        </div>
                    </div>
                    <div class="widget-content">
                        <div class="table-responsive">
                            <table data-sortable class="table table-hover table-striped">
                                <thead>
                                <tr>
                                    <th>权限ID</th>
                                    <th>权限名称</th>
                                    <th>控制器名称</th>
                                    <th>方法名称</th>
                                    <th style="text-align: center;">操作</th>
                                   
                                </tr>
                                </thead>

                                <tbody>
                                	{volist name="list" id="vo"}
                                <tr>
                                    <td>{$vo.id}</td>
                                    <td><strong>{$vo.pri_name}</strong></td>
                                    <td><strong>{$vo.controller_name}</strong></td>
                                    <td><strong>{$vo.action_name}</strong></td>
                                   	<td>
                                    	<button class="btn btn-primary btn-sm" data-toggle="modal"  onclick="ajaxEdit({$vo.id})">编辑</button>
                                      <!--
                                      	作者：554321082@qq.com
                                      	时间：2019-08-01
                                      	描述：<button type="button" class="btn btn-danger btn-sm" onclick="ajaxDel({$vo.id})">删除</button>
                                      -->  
                                         <button type="button" class="btn btn-danger btn-sm" onclick="l({$vo.id})">删除</button>
                                    </td>
                                   
                                </tr>
                               {/volist}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>

            </div>
            
           
<!-- 编辑用户模态框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header" style="text-align: center;">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">编辑权限</h4>
            </div>
            <div class="modal-body clearfix">
            	 <form id="edit">
            	 	<div class="col-md-2"> </div>
        	<table class="table-bordered col-md-8"  style="text-align: center;;border-collapse:separate;border-spacing:10px 10px;">
					
        		<trbody>
        			<tr>
        				<input type="hidden" name="id" id="pid" />
        			<td>
        				权限名
        			</td>
        			<td>
        				<p style="margin-top:10px;">
        				<input type="text" name="pri_name" id="ep"> 
        				</p>
        			</td>
        		</tr>
        		<tr>
        			<td>控制器名称</td>
        			<td>
        				<p style="margin-top:10px;">
        				<input type="text" name="controller_name" id="ec"> 
        				</p>
        			</td>
        		</tr>
        		<tr>
        			<td>方法名称</td>
        			<td>
        				<p style="margin-top:10px;">
        				<input type="text" name="action_name" id="ea"> 
        				</p>
        			</td>
        		</tr>
        		
        		
        		</trbody>
        	</table>
        	 </form>
        	
        
            </div>
            <div class="modal-footer" style="text-align: center;">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="ajaxPost()">提交更改</button>
            </div>
           
        </div>
    </div>
</div>

   	<!-- Footer Start -->
        <footer class="col-md-12">
            Huban Creative &copy; 2014
            <div class="footer-links pull-right">
                <a href="#">About</a><a href="#">Support</a><a href="#">Terms of Service</a><a href="#">Legal</a><a
                    href="#">Help</a><a href="#">Contact Us</a>
            </div>
        </footer>
        <!-- Footer End -->
    </div>
    <!-- ============================================================== -->
    <!-- End content here -->
    <!-- ============================================================== -->

</div>
<!-- End right content -->

{/block}